
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta charset="utf-8"></meta>
      <meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
      <title>8.6.&nbsp;Bolt - Chapter&nbsp;8.&nbsp;Database Integration</title>
      <link rel="stylesheet" type="text/css" href="../../docbook.css"></link>
      <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,300italic"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/theme/neo.min.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/chunked-base.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/extra.css"></link><script src="//code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script><script src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js" type="text/javascript"></script><script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/addon/runmode/runmode.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/mode/cypher/cypher.min.js" type="text/javascript"></script><script src="../../javascript/datatable.js" type="text/javascript"></script><script src="../../javascript/colorize.js" type="text/javascript"></script><script src="../../javascript/tabs-for-chunked.js" type="text/javascript"></script><script src="../../javascript/mp-nav.js" type="text/javascript"></script><script src="../../javascript/versionswitcher.js" type="text/javascript"></script><script src="../../javascript/version.js" type="text/javascript"></script><script src="//s3-eu-west-1.amazonaws.com/alpha.neohq.net/docs/new-manual/assets/search.js" type="text/javascript"></script><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"></meta>
      <link rel="prev" href="../couchbase/" title="8.5.&nbsp;Interacting with Couchbase"></link>
      <link rel="next" href="../load-ldap/" title="8.7.&nbsp;Load LDAP"></link>
      <link rel="shortcut icon" href="https://neo4j.com/wp-content/themes/neo4jweb/favicon.ico"></link><script>
        $(document).ready(function() {
          CodeMirror.colorize();
          tabTheSource($('body'));
          var $header = $('header').first();
          $header.prepend(
            $('<a href="" id="logo"><img src="https://neo4j.com/wp-content/themes/neo4jweb/assets/images/neo4j-logo-2015.png" alt="Neo4j Logo"></img></a>')
          );
          var $sidebar = $('<div id="sidebar-wrapper"></div>');
          $.get('toc.html', function (d){
            $(d).appendTo($sidebar);
            highlightToc();
            highlightLibraryHeader();
          });
          $sidebar.insertAfter($('header').first());
        });
        </script></head>
   <body>
      <header>
         <div class="searchbox">
            <form id="search-form" class="search" name="search-form" role="search"><input id="search-form-input" name="q" title="search" type="search" lang="en" placeholder="Search Neo4j docs..." aria-label="Search Neo4j documentation" max-length="128" required="required"></input><input id="search-form-button" type="submit" value="Search"></input></form>
         </div>
         <ul class="documentation-library">
            <li><a href="https://neo4j.com/docs/operations-manual/current">Operations Manual</a></li>
            <li><a href="https://neo4j.com/docs/developer-manual/current/">Developer Manual</a></li>
            <li><a href="https://neo4j.com/docs/ogm-manual/current/">OGM Manual</a></li>
            <li><a href="https://neo4j.com/docs/graph-algorithms/current/">Graph Algorithms</a></li>
            <li><a href="https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.4/">APOC</a></li>
            <li><a href="https://neo4j.com/docs/java-reference/current/">Java Reference</a></li>
         </ul>
         <nav id="header-nav"><span class="nav-previous"><a accesskey="p" href="../couchbase/"><span class="fa fa-long-arrow-left" aria-hidden="true"></span>Interacting with Couchbase</a></span><span class="nav-current">
               <p class="nav-title hidden">8.6.&nbsp;Bolt</p></span><span class="nav-next"><a accesskey="n" href="../load-ldap/">Load LDAP<span class="fa fa-long-arrow-right" aria-hidden="true"></span></a></span></nav>
      </header>
      <div id="search-results" class="hidden"></div>
      <section class="section" id="bolt-neo4j">
         <div class="titlepage">
            <div>
               <div>
                  <h2 class="title" style="clear: both"><a class="anchor" href="#bolt-neo4j"></a>8.6.&nbsp;Bolt
                  </h2>
               </div>
            </div>
         </div>
         <p>Bolt procedures allows to accessing other databases via bolt protocol.</p>
         <div class="informaltable">
            <div class="table" id="d0e10155">
               <table class="informaltable" border="1">
                  <colgroup>
                     <col class="col_1"></col>
                     <col class="col_2"></col>
                  </colgroup>
                  <tbody>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">CALL apoc.bolt.execute(urlOrKey, statement, params, config) YIELD row</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>access to other databases via bolt for read and write</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">CALL apoc.bolt.load(urlOrKey, statement, params, config) YIELD row</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>access to other databases via bolt for read</p>
                        </td>
                     </tr>
                  </tbody>
               </table>
            </div>
         </div>
         <p><span class="strong"><strong>urlOrKey</strong></span> param allows users to decide if send url by apoc or if put it into neo4j.conf file.
         </p>
         <div class="itemizedlist">
            <ul class="itemizedlist" style="list-style-type: disc; ">
               <li class="listitem"><span class="strong"><strong>apoc</strong></span> : write the complete url in his right position on the apoc.
               </li>
            </ul>
         </div><pre class="programlisting highlight"><code data-lang="cypher">call apoc.bolt.load("bolt://user:password@localhost:7687","match(p:Person {name:{name}}) return p", {name:'Michael'})</code></pre><div class="itemizedlist">
            <ul class="itemizedlist" style="list-style-type: disc; ">
               <li class="listitem"><span class="strong"><strong>neo4j.conf</strong></span> : here the are two choices:
               </li>
            </ul>
         </div>
         <p>1) <span class="strong"><strong>complete url</strong></span>: write the complete url with the param apoc.bolt.url;
         </p>
         <p><span class="formalpara-title">apoc.&nbsp;</span>
            
         </p><pre class="programlisting highlight"><code data-lang="cypher">call apoc.bolt.load("","match(p:Person {name:{name}}) return p", {name:'Michael'})</code></pre><p>
            
         </p>
         <p><span class="formalpara-title">neo4jConf.&nbsp;</span>
            
         </p><pre class="programlisting highlight"><code data-lang="txt">//simple url
apoc.bolt.url=bolt://user:password@localhost:7687</code></pre><p>
            
         </p>
         <p>2) <span class="strong"><strong>by key</strong></span>: set the url with a personal key apoc.bolt.yourKey.url; in this case in the apoc on the url param user has to insert the
            key.
         </p>
         <p><span class="formalpara-title">apoc.&nbsp;</span>
            
         </p><pre class="programlisting highlight"><code data-lang="cypher">call apoc.bolt.load("test","match(p:Person {name:{name}}) return p", {name:'Michael'})</code></pre><p>
            
         </p>
         <p><span class="formalpara-title">neo4jConf.&nbsp;</span>
            
         </p><pre class="programlisting highlight"><code data-lang="txt">//with key
apoc.bolt.test.url=bolt://user:password@localhost:7687
apoc.bolt.production.url=bolt://password:test@localhost:7688</code></pre><p>
            
         </p>
         <p>Config available are:</p>
         <div class="itemizedlist">
            <ul class="itemizedlist" style="list-style-type: disc; ">
               <li class="listitem"><code class="literal">statistics</code>: possible values are true/false, the default value is false. This config print the execution statistics;
               </li>
               <li class="listitem"><code class="literal">virtual</code>: possible values are true/false, the default value is false. This config return result in virtual format and not in map format,
                  in apoc.bolt.load.
               </li>
            </ul>
         </div>
         <section class="section" id="_driver_configuration">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_driver_configuration"></a>8.6.1.&nbsp;Driver configuration
                     </h3>
                  </div>
               </div>
            </div>
            <p>To set the configuration of the Driver, you can add the parameter <code class="literal">driverConfig</code> in the config.
               Is&#8217;s a map of values, the values that we don&#8217;t pass to the config, are set to the default value.
            </p><pre class="programlisting highlight"><code data-lang="cypher">{logging='INFO', encryption=true, logLeakedSessions:true, maxIdleConnectionPoolSize:10, idleTimeBeforeConnectionTest:-1, trustStrategy:'TRUST_ALL_CERTIFICATES',
 routingFailureLimit: 1, routingRetryDelayMillis:5000, connectionTimeoutMillis:5000, maxRetryTimeMs:30000 }</code></pre><div class="informaltable">
               <div class="table" id="d0e10259">
                  <table class="informaltable" border="1">
                     <colgroup>
                        <col class="col_1"></col>
                        <col class="col_2"></col>
                        <col class="col_3"></col>
                     </colgroup>
                     <thead>
                        <tr>
                           <th style="text-align: left; vertical-align: top; ">param</th>
                           <th style="text-align: left; vertical-align: top; ">description</th>
                           <th style="text-align: left; vertical-align: top; ">possible values/ types</th>
                        </tr>
                     </thead>
                     <tbody>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>logging</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>logging provider to use</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>INFO, WARNING, OFF, SEVERE, CONFIG, FINE, FINER</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>encryption</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Disable or enabled encryption</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>true, false</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>logLeakedSessions</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Disable or enable logging of leaked sessions</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>true, false</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>maxIdleConnectionPoolSize</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Max number of connections</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>number</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>idleTimeBeforeConnectionTest</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Pooled connections that have been idle in the pool for longer than this timeout</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Milliseconds</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>trustStrategy</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Specify how to determine the authenticity of an encryption certificate provided by the Neo4j instance we are connecting to</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>TRUST_ALL_CERTIFICATES, TRUST_SYSTEM_CA_SIGNED_CERTIFICATES, or directly a custom certificate</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>routingFailureLimit</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>the number of times to retry each server in the list of routing servers</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>number</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>routingRetryDelayMillis</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Specify how long to wait before retrying to connect to a routing server</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Milliseconds</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>connectionTimeoutMillis</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Specify socket connection timeout</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Milliseconds</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>maxRetryTimeMs</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Specify the maximum time transactions are allowed to retry</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Milliseconds</p>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
            <p>You can find all the values in the documentation <a class="link" href="http://neo4j.com/docs/api/java-driver/current/org/neo4j/driver/v1/Config.ConfigBuilder.html" target="_top">Config.ConfigBuilder</a></p>
         </section>
         <section class="section" id="_bolt_examples">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_bolt_examples"></a>8.6.2.&nbsp;Bolt Examples
                     </h3>
                  </div>
               </div>
            </div>
            <p><span class="strong"><strong>Return node in map format</strong></span></p><pre class="programlisting highlight"><code data-lang="cypher">call apoc.bolt.execute("bolt://user:password@localhost:7687",
"match(p:Person {name:{name}}) return p", {name:'Michael'})</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.bolt.execute.nodemap.PNG" width="800" alt="apoc.bolt.execute.nodemap"></img></div>
            </div>
            <p><span class="strong"><strong>Return node in virtual Node format</strong></span></p><pre class="programlisting highlight"><code data-lang="cypher">call apoc.bolt.load("bolt://user:password@localhost:7687",
"match(p:Person {name:{name}}) return p", {name:'Michael'}, {virtual:true})</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.bolt.load.virtualnode.PNG" width="800" alt="apoc.bolt.load.virtualnode"></img></div>
            </div>
            <p><span class="strong"><strong>Create node and return statistic</strong></span></p><pre class="programlisting highlight"><code data-lang="cypher">call apoc.bolt.execute("bolt://user:password@localhost:7687",
"create(n:Node {name:{name}})", {name:'Node1'}, {statistics:true})</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.bolt.execute.createandstatistics.PNG" width="800" alt="apoc.bolt.execute.createandstatistics"></img></div>
            </div>
            <p><span class="strong"><strong>Return more scalar values</strong></span></p><pre class="programlisting highlight"><code data-lang="cypher">call apoc.bolt.execute("bolt://user:password@localhost:7687",
"match (n:Person {name:{name}}) return n.age as age, n.name as name, n.surname as surname", {name:'Michael'})</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.bolt.execute.scalarmulti.PNG" width="800" alt="apoc.bolt.execute.scalarmulti"></img></div>
            </div>
            <p><span class="strong"><strong>Return relationship in a map format</strong></span></p><pre class="programlisting highlight"><code data-lang="cypher">call apoc.bolt.load("bolt://user:password@localhost:7687",
"MATCH (n:Person{name:{name}})-[r:KNOWS]-&gt;(p) return r as rel", {name:'Anne'})</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.bolt.load.relmap.PNG" width="800" alt="apoc.bolt.load.relmap"></img></div>
            </div>
            <p><span class="strong"><strong>Return virtual path</strong></span></p><pre class="programlisting highlight"><code data-lang="cypher">call apoc.bolt.load("bolt://user:password@localhost:7687",
"START n=node({idNode}) MATCH path= (n)-[r:REL_TYPE*..3]-&gt;(o) return path", {idNode:200}, {virtual:true})</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.bolt.load.returnvirtualpath.PNG" width="800" alt="apoc.bolt.load.returnvirtualpath"></img></div>
            </div>
            <p><span class="strong"><strong>Create a Node with params in input</strong></span></p><pre class="programlisting highlight"><code data-lang="cypher">call apoc.bolt.execute("bolt://user:password@localhost:7687",
"CREATE (n:Car{brand:{brand},model:{model},year:{year}}) return n", {brand:'Ferrari',model:'California',year:2016})</code></pre><div class="informalfigure">
               <div class="mediaobject"><img src="https://raw.githubusercontent.com/neo4j-contrib/neo4j-apoc-procedures/3.4/docs/images/apoc.bolt.execute.createwithparams.PNG" width="800" alt="apoc.bolt.execute.createwithparams"></img></div>
            </div>
         </section>
      </section>
      <footer><script type="text/javascript">
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
          //Allow Linker
          ga('create', 'UA-1192232-34','auto', {'allowLinker': true});
          ga('send', 'pageview');
          // Load the plugin.
          ga('require', 'linker');
          // Define which domains to autoLink.
          ga('linker:autoLink', ['neo4j.org','neo4j.com','neotechnology.com','graphdatabases.com','graphconnect.com']);
        </script><script type="text/javascript">
          document.write(unescape("%3Cscript src='//munchkin.marketo.net/munchkin.js' type='text/javascript'%3E%3C/script%3E"));
        </script><script>Munchkin.init('773-GON-065');</script></footer>
   </body>
</html>